import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $fn } = window
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		selectedKeys:[]
	}
	
	open = uuid  => {
		this.modal.open()
		this.query = { uuid }
		this.submit = { uuid }
		this.fetch()
	}
	
	// 表单
	cols = [
		{ title: '模板代码', 	dataIndex: 'name'},
		{ title: '模板名称', 	dataIndex: 'remark' },
	]
	
	// paging
	fetch = () => $fn.fetch.call(this,'printer/assocTmpl', { paging:'get' } ).then(data=>{
		
		this.setState(({ selectedKeys }) => {
			data.forEach( ({ assoc, value }) => {
				if(+assoc === 1) {
					selectedKeys.push(value)
				}
			} )
			return { selectedKeys: [ ...selectedKeys ] }
		})
	})

	render(){
		return (
			<>
				{
					TableModal.call(this,{
						title:'关联模板', width:'70%', minWidth:700, height:'70%',  api:'printer/assocTmpl', idStr:'value',
						getSubmit: tmpl_codes => ( { tmpl_codes } ),
					})
				}
			</>
		)
	}
}

export default Index